package com.yidu.service.impl;

import com.yidu.entity.DbUser;
import com.yidu.dao.DbUserDao;
import com.yidu.service.DbUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (DbUser)表服务实现类
 *
 * @author makejava
 * @since 2021-07-30 09:18:58
 */
@Service("dbUserService")
public class DbUserServiceImpl implements DbUserService {
    @Resource
    private DbUserDao dbUserDao;

    /**
     * 通过ID查询单条数据
     *
     * @param userid 主键
     * @return 实例对象
     */
    @Override
    public DbUser queryById(Integer userid) {
        return this.dbUserDao.queryById(userid);
    }

    /**
     * 查询多条数据
     *
     * @param user
     * @return 对象列表
     */
    @Override
    public List<DbUser> queryAllByLimit(DbUser user) {
        return this.dbUserDao.queryAllByLimit(user);
    }

    /**
     * 新增数据
     *
     * @param dbUser 实例对象
     * @return 实例对象
     */
    @Override
    public DbUser insert(DbUser dbUser) {
        this.dbUserDao.insert(dbUser);
        return dbUser;
    }

    /**
     * 修改数据
     *
     * @param dbUser 实例对象
     * @return 实例对象
     */
    @Override
    public DbUser update(DbUser dbUser) {
        this.dbUserDao.update(dbUser);
        return this.queryById(dbUser.getUserid());
    }

    /**
     * 通过主键删除数据
     *
     * @param userid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer userid) {
        return this.dbUserDao.deleteById(userid) > 0;
    }

    /**
     * 通过账号密码查询单个用户
     * @param user
     * @return
     */
    @Override
    public DbUser findLogin(DbUser user) {
        return this.dbUserDao.findLogin(user);
    }

    @Override
    public DbUser findLoginName(String userName, String userPwd) {
        return this.dbUserDao.findLoginName(userName,userPwd);
    }

    @Override
    public DbUser findByName(String userName) {
        return this.dbUserDao.findByName(userName);
    }

    @Override
    public int findCount(DbUser user) {
        return this.dbUserDao.findCount(user);
    }

}
